/**
 * ReportGear(2011)
 */
package com.reportgear.designer.action.edit;

import java.awt.event.ActionEvent;

import com.reportgear.designer.action.ReportAction;
import com.reportgear.report.context.ReportContext;
import com.reportgear.report.model.ReportModel;
import com.reportgear.report.view.JWorksheet;
import com.reportgear.report.view.grid.Grid;
import com.reportgear.report.view.grid.selection.GridSelection;
import com.reportgear.report.view.grid.selection.Selection;

/**
 * 清除单元格内容Action
 * 
 * @version 1.0 2011-6-13
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class ClearValueAction extends ReportAction {
	public ClearValueAction() {
		this.setName("清除单元格");
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JWorksheet worksheet = ReportContext.INSTANCE.getCurrentWorkSheet();
		if (worksheet == null) {
			return;
		}

		GridSelection gridSel = worksheet.getGridSelection();
		Grid grid = worksheet.getGrid();
		if (grid.isCellSelectable()) {
			try {
				Selection sel = gridSel.getEditSelection();
				ReportModel report = worksheet.getReportModel();

				report.setCellValue(sel, null);
				
				//TODO 确认这儿更新
				worksheet.refresh();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}
}
